package net.cctms.zhishu.webAppFramework.ui.view;

import android.app.Dialog;
import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.widget.AdapterView;
import android.widget.GridView;


import net.cctms.zhishu.R;
import net.cctms.zhishu.webAppFramework.adapter.ShareItemAdapter;

/**
 * 分享对话框
 * Created by yanfei on 2017/8/9.
 */
public class ShareDialog extends Dialog {
    private Context context;
    private View contentView;
    private GridView shareItemGv;

    private ShareItemAdapter shareItemAdapter;
    /**
     * 微信朋友圈
     */
    public static final int WEIXIN_FRIENDS = 0;
    /**
     * 微信好友
     */
    public static final int WEXIN = 1;
    /**
     * qq空间
     */
    public static final int QZONE = 2;
    /**
     * qq好友
     */
    public static final int QQ = 3;
    /**
     * 微博
     */
    public static final int WEIBO = 4;
    /**
     * 短信
     */
    public static final int SMS = 5;

    private boolean isShareActivity = false;

    private OnShareItemClickListener onShareItemClickListener;

    public ShareDialog(Context context) {
        super(context, R.style.CommonDialog);
        this.context = context;
    }

    public ShareDialog(Context context,boolean isShareActivity) {
        super(context, R.style.CommonDialog);
        this.context = context;
        this.isShareActivity = isShareActivity;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        init();
    }

    public void setOnItemClickListener(OnShareItemClickListener onShareItemClickListener) {
        this.onShareItemClickListener = onShareItemClickListener;
    }

    private void init() {
        LayoutInflater inflater = LayoutInflater.from(context);
        contentView = inflater.inflate(R.layout.share_window_layout, null);
        setContentView(contentView);

        shareItemGv = (GridView) contentView.findViewById(R.id.share_window_item_gv);
        shareItemGv.setSelector(new ColorDrawable(Color.TRANSPARENT));
        shareItemAdapter = new ShareItemAdapter(context);
        shareItemAdapter.setIsInVisibleSms(true);
        shareItemGv.setAdapter(shareItemAdapter);
        initListener();

        Window window = getWindow();
        window.setWindowAnimations( R.style.dialogWindowAnim);

    }

    private void initListener() {
        shareItemGv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                if (position == SMS) {
                    return;
                }
                dismiss();
                if (onShareItemClickListener != null) {
                    onShareItemClickListener.onShareItemClick(position);
                }
            }
        });
    }

    public interface OnShareItemClickListener {
        void onShareItemClick(int position);
    }

}

